<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>直播间视频</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/lib/imageview/css/imageviewer.css"
          th:href="@{/resource/lib/imageview/css/imageviewer.css}" rel="stylesheet"/>

    <script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
    <script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
    <script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
            th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316(123123)}"></script>
    <script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316"
            th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"></script>
    <style>
        .user-close-config {
            height: 40px;
            line-height: 40px;
        }

        .user-close-config .control-label {
            margin-left: 20px;
            font-weight: normal !important;
        }

        .user-close-config label.off {
            background-color: red;
            color: #fff;
            margin-right: 10px;
        }

        .user-close-config label.on {
            background-color: #fff;
            color: #674646;
            border: 1px solid #ccc;
            margin-right: 10px;
        }

        .separator {
            margin: 31px 20px 10px 20px;
            border-bottom: 1px solid #ccc;
        }
    </style>
</head>

<body>
<div class="wrapper wrapper-content tooltip-demo">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div th:replace="fragments/live_fragment::roomDetailFg" class="ibox-title"
                     style="vertical-align: bottom;height: 100%;padding-left: 0;">
                    <h5 style="font-size: 18px;">
                        <img src="../../resource/img/p2.jpg" onerror="this.src='../../resource/img/d_head.jpeg'"
                             alt="" style="width:100px;height:100px;"/>
                    </h5>
                    <div style="margin-left: 120px;width: 50%;margin-top: -6px;">
                        <h3>剑南的直播间</h3>
                        <p style="width: 373px;height: 51px;">
                            非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间</p>
                        <p>创建时间：2012-12-12 12:12:12</p>
                    </div>
                    <button type="button" onclick="liveHandler.edit()"
                            style="float: right;margin-top: -45px;margin-right: 10px;"
                            class="btn btn-primary btn-xl m-b-none">房间设置
                    </button>
                </div>
                <div class="tabs-container" style="margin-top: 20px;">
                    <ul class="nav nav-tabs">
                        <li>
                            <a th:href="@{/live/detail/products(roomId=${room.id})}" href="user_detail.html">商品管理</a>
                        </li>
                        <li>
                            <a th:href="@{/live/detail/directors(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">主播管理</a>
                        </li>
                        <li>
                            <a th:href="@{/live/detail/sessions(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">直播记录</a>
                        </li>
                        <li class="active">
                            <a th:href="@{/live/detail/videos(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">直接间视频</a>
                        </li>
                        <li sec:authorize="hasRole('ADMIN')">
                            <a th:href="@{/live/detail/images(roomId=${room.id})}"
                               href="../live/live_detail_images.html">直接间图片</a>
                        </li>
                        <li sec:authorize="hasRole('ADMIN')">
                            <a th:href="@{/live/detail/users(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">直接间用户列表</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <div>
                                    <form id="saveForm">
                                        <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                                    </form>
                                    <div class="form-inline" style="padding-bottom: 15px;text-align: right;">
                                        <button type="button" onclick="liveHandler.createModalShow()"
                                                class="btn btn-primary btn-sm m-b-none">添加直播视频
                                        </button>
                                    </div>
                                    <div class="table-responsive">
                                        <table class="table table-bordered table-hover table-center">
                                            <thead>
                                            <tr>
                                                <th>视频ID</th>
                                                <th>视频主题</th>
                                                <th>视频链接</th>
                                                <th>是否已播放</th>
                                                <th>最后播放时间</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr th:each="item:${list}">
                                                <td th:text="${item.id}">123123123</td>
                                                <td th:text="${item.title}"></td>
                                                <td>
                                                    <a target="_blank" th:href="${item.videoUrl}">点击打开视频</a>
                                                </td>
                                                <td>
                                                    <span th:text="${item.pushed?'是':'否'}"></span>
                                                </td>
                                                <td th:text="${#temporals.format(item.pushTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                                <td>
                                                    <button th:if="${!item.pushed}" onclick="liveHandler.push(1)"
                                                            th:onclick="liveHandler.push([[${item.id}]])"
                                                            type="button"
                                                            class="btn btn-danger btn-xs m-b-none"
                                                            style="margin-left: 5px;">播放
                                                    </button>
                                                    <button th:if="${item.pushed}" onclick="liveHandler.close(1)"
                                                            th:onclick="liveHandler.close([[${item.id}]])"
                                                            type="button"
                                                            class="btn btn-danger btn-xs m-b-none"
                                                            style="margin-left: 5px;">停止播放
                                                    </button>
                                                    <button onclick="liveHandler.delete(1)"
                                                            th:onclick="liveHandler.delete([[${item.id}]])"
                                                            type="button"
                                                            class="btn btn-info btn-xs m-b-none"
                                                            style="margin-left: 5px;">删除
                                                    </button>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <p style="float: left; margin: 20px 0;">
                                        共<span th:text="${totalRecords}"></span>条记录，当前第<span
                                            th:text="${pageIndex}"></span>/<span
                                            th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                    </p>
                                    <ul style="float: right;" class="pagination pagination-split">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<input class="file" type="file" id="uploadfileVideo" name="img"
       style="display: none;"
       accept="video/mp4" view-element=".videoPreview"
       val-element="#videoUrl"/>
<script type="text/html" id="create_video_template">
    <div class="form-horizontal" style="width: 600px;">
        <div class="form-group">
            <label class="col-sm-2 control-label">视频标题:</label>
            <div class="col-sm-10">
                <input id="create_videoTitle" class="form-control" placeholder="直播标题">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label" style="padding-top:70px;">上传视频</label>
            <div class="col-sm-4">
                <input type="hidden" name="videoUrl" id="videoUrl"/>
                <a title="选择视频">
                    <img class="videoPreview" src="../../resource/img/bg.png"
                         onerror="this.src='/resource/img/bg.png'"
                         style="margin-top: 10px; width:150px;height:150px;"
                    />
                </a>
            </div>
        </div>
    </div>
</script>


<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="../../resource/hotui/js/plugins/ajaxfileupload.js"
        th:src="@{/resource/hotui/js/plugins/ajaxfileupload.js}"></script>
<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/live/detail/videos}]]*/  "";
    const apiUri = /*[[@{/live/detail/videos}]]*/  "";
    const uploadUri = /*[[@{/resource/upload}]]*/  "";

</script>

<script type="text/javascript">
    let createModal = $("#create_video_template").modal("添加直播视频", function () {
        liveHandler.create();
    });
    $(function () {
        //初始化分页
        let pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            liveHandler.search(p);
        });
        $("#uploadfileVideo").change(function () {
            let $view = $(this).attr('view-element');
            let $val = $(this).attr('val-element');
            hot.loading.show();
            hot.fileUpload(uploadUri, $(this).attr('id'), null, function (apiResult) {
                hot.loading.close();
                if (apiResult.resultCode === 2000) {
                    $($view).attr("src", '/resource/img/video_ok.jpg');
                    $($val).val(apiResult.data.previewUrl);
                }
            });
        });
    });

    let liveHandler = {
        search: function (pageIndex) {
            let roomId = $("#hdRoomId").val();
            window.location.href = pageUri + "?roomId=" + roomId + "&pageIndex=" + pageIndex;
        },
        createModalShow: function () {
            let options = {
                btn: ["保存视频", "取消"]
            };
            createModal.show(function () {
                //上传
                $('.videoPreview').click(function () {
                    $("#uploadfileVideo").click();
                });
            }, options);
        },
        create: function () {
            let roomId = $("#hdRoomId").val();
            let videoUrl = $("#videoUrl").val();
            let title = $("#create_videoTitle").val();
            if (typeof videoUrl === "undefined" || videoUrl === "" || typeof title === "undefined" || title === "") {
                return;
            }

            let requestData = {
                roomId: roomId,
                videoUrl: videoUrl,
                title: title
            };

            hot.ajax(apiUri + "/sendVideoMessage", requestData, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    }, 500)
                } else {
                    hot.tip.error("操作失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post", 300);
        },
        delete(id) {
            hot.confirm("是否删除当前视频？，此操作会关闭客户端正在播放的视频！", function () {
                hot.ajax(apiUri + "/delete", {id: id}, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("删除成功", function () {
                            window.location.reload();
                        }, 500);
                    } else {
                        hot.tip.error("删除失败");
                    }
                }, function () {
                }, "get", 300);
            });
        },
        push(id) {
            hot.ajax(apiUri + "/push", {id: id}, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("发送成功", function () {
                        window.location.reload();
                    }, 500);
                } else {
                    hot.tip.error("发送失败" + apiResult.resultMsg);
                }
            }, function () {
            }, "get", 300);
        },
        /**
         * 关闭视频播放
         * @param id
         */
        close(id) {
            hot.ajax(apiUri + "/close", {id: id}, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("断播成功", function () {
                        window.location.reload();
                    }, 500);
                } else {
                    hot.tip.error("断播失败" + apiResult.resultMsg);
                }
            }, function () {
            }, "get", 300);
        }
    }
</script>
</body>

</html>